package cn.elwy.rcp.ui.explorer.process;

import java.lang.reflect.InvocationTargetException;

import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jface.operation.IRunnableWithProgress;

import cn.elwy.rcp.core.model.ui.progress.ProgressMonitor;
import cn.elwy.rcp.ui.explorer.core.AppContext;
import cn.elwy.rcp.ui.explorer.core.service.SvnManageService;
import cn.elwy.rcp.ui.explorer.core.vo.ProjectConfig;

/**
 * 更新SVN代码进程
 * @author huangsq
 * @version 1.0, 2014-10-15
 * @since 1.0, 2014-10-15
 */
public class SvnUpdateProgress implements IRunnableWithProgress {

	private SvnManageService svnManageService = AppContext.getService(SvnManageService.ID, SvnManageService.class);
	private static final int TOTAL_TIME = 5000;
	private static final int INCREMENT = 500;
	private boolean indeterminate;
	private ProjectConfig projectConfig;

	public SvnUpdateProgress(ProjectConfig projectConfig) {
		this.projectConfig = projectConfig;
	}

	public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
		ProgressMonitor progressMonitor = new ProgressMonitor(monitor);
		// monitor.beginTask("更新SVN代码", indeterminate ? IProgressMonitor.UNKNOWN : TOTAL_TIME);
		try {
			svnManageService.checkOut(projectConfig, progressMonitor);
		} finally {
			monitor.done();
		}
		if (monitor.isCanceled()) {
			throw new InterruptedException("The long running operation was cancelled");
		}
	}
}
